<?php
$mParent = $this->mPadres;
$builder = $mParent->builder;
$builder->db = $this->db;

$db = $this->db;
$tabs = $db->query_select('cllg_table_tab', "TABLE_NAME='$mParent->table'");

$sql = sprintf("select * from cllg_parent where ID=%s", getParam('IDP'));
$rows = $db->queryToArray($sql,false);
$row = $rows[0];

$arrFecNac = array();
$arrFecNac = explode("-", $row["FEC_NAC"]);
krsort($arrFecNac);
$row["FEC_NAC"] = implode("-", $arrFecNac);
$arrFecNacC = array();
$arrFecNacC = explode("-", $row["FEC_NAC_C"]);
krsort($arrFecNacC);
$row["FEC_NAC_C"] = implode("-", $arrFecNacC);
?>

<form id="<?php echo $mParent->formName; ?>" name="<?php echo $mParent->formName; ?>"
      method="post" action="<?php echo CORE_PATH; ?>">
    <input type="hidden" id="module" name="module" value="<?php echo $this->instanceName; ?>" />
    <div id="mant_head" class="ui-widget-content ui-corner-all">
        <div id="titulo">Datos Familiar</div>
        <div id="botones">
            <button id="cmdOk" type="button" onclick="doSubmit('operation=u')">
                <img alt=""  src="imgv2/actions/document-save.png" />
            </button>
            <button id="cmdCancel" type="submit">
                <img alt=""  src="imgv2/actions/window-close.png" />
            </button>
        </div>
    </div>
    <div id="tabs">
        <ul>
            <li><a href="#tab1">INFORMACION PRINCIPAL</a></li>
            <?php
            foreach ($tabs as $t) {
                $ix = $t["ID"];
                $tabId = "_tab_" . $ix;
            ?>
                <li ><a href="#<?php echo $tabId; ?>"><?php echo $t["CAPTION"]; ?></a></li>
            <?php
            }
            ?>
        </ul>
        <div class="form-container" id="tab1">
            <fieldset>
                <input name="ID" readonly="readonly" value="<?php echo $row["ID"]; ?>" type="hidden" id="ID"  />
                <div>
                    <label for="DOCTO_ID">* Tipo Identificación:</label>
                    <select name="DOCTO_ID" size="1" id="DOCTO_ID">
                        <option <?php
            if (!(strcmp("C", $row['DOCTO_ID']))) {
                echo "selected=\"selected\"";
            }
            ?> value="C">Cedula</option>
                        <option <?php
                            if (!(strcmp("L", $row['DOCTO_ID']))) {
                                echo "selected=\"selected\"";
                            } ?> value="L">Licencia</option>
                        <option <?php
                            if (!(strcmp("P", $row['DOCTO_ID']))) {
                                echo "selected=\"selected\"";
                            }
            ?> value="P">Pasaporte</option>
                    </select>
                </div>
                <div>
                    <label for="NUMERO_ID">* Identificaci&oacute;n:</label>
                    <input name="NUMERO_ID" value="<?php echo $row["NUMERO_ID"]; ?>" type="text" id="NUMERO_ID"  />
                </div>
                <div>
                    <label for="RELACION">* Relaci&oacute;n Familiar:</label>
                    <select name="RELACION" size="1" id="RELACION">
                        <option <?php
                            if (!(strcmp("P", $row['RELACION']))) {
                                echo "selected=\"selected\"";
                            } ?> value="P">PADRE</option>
                        <option <?php
                            if (!(strcmp("M", $row['RELACION']))) {
                                echo "selected=\"selected\"";
                            }
            ?> value="M">MADRE</option>
                        <option <?php
                            if (!(strcmp("T", $row['RELACION']))) {
                                echo "selected=\"selected\"";
                            }
            ?> value="T">TIO(A)</option>
                        <option <?php
                            if (!(strcmp("A", $row['RELACION']))) {
                                echo "selected=\"selected\"";
                            }
            ?> value="A">ABUELO(A)</option>
                        <option <?php
                            if (!(strcmp("H", $row['RELACION']))) {
                                echo "selected=\"selected\"";
                            }
            ?> value="H">HERMANO(A)</option>
                    </select>
                </div>
                <div>
                    <label for="NOMBRE_A">* Nombres:</label>
                    <input name="NOMBRE_A" type="text" value="<?php echo $row["NOMBRE_A"]; ?>" id="NOMBRE_A" size="50" maxlength="100" />
                </div>
                <div>
                    <label for="DOCTO_ID">* Apellidos:</label>
                    <input name="APELLIDO_A"  type="text" id="APELLIDO_A" value="<?php echo $row["APELLIDO_A"]; ?>" size="50" maxlength="100" />
                </div>
               <!-- <div>
                    <label for="SEXO">* Sexo:</label>
                    
                    <select name="SEXO" size="1" id="SEXO">
                        <option value="M" <?php
                            if (!(strcmp("M", $row['SEXO']))) {
                                echo "selected=\"selected\"";
                            }
            ?>>Masculino</option>
                        <option value="F" <?php
                                if (!(strcmp("F", $row['SEXO']))) {
                                    echo "selected=\"selected\"";
                                }
            ?>>Femenino</option>
                    </select>
                </div>-->
                <div>
                    <label for="FEC_NAC">* Fecha Nacimiento:</label>
                    <input name="FEC_NAC" type="text" id="FEC_NAC" value="<?php echo $row["FEC_NAC"]; ?>" />
                    <input name="STATUS" type="hidden" id="STATUS" value="1" />
                </div>
            </fieldset>
            <fieldset>
                <div>
                    <label for="DOCTO_ID_C">Tipo Identificación:</label>
                    <select name="DOCTO_ID_C" size="1" id="DOCTO_ID_C">
                        <option <?php
                                if (!(strcmp("C", $row['DOCTO_ID_C']))) {
                                    echo "selected=\"selected\"";
                                }
            ?> value="C">Cedula</option>
                            <option <?php
                                if (!(strcmp("L", $row['DOCTO_ID_C']))) {
                                    echo "selected=\"selected\"";
                                } ?> value="L">Licencia</option>
                            <option <?php
                                if (!(strcmp("P", $row['DOCTO_ID_C']))) {
                                    echo "selected=\"selected\"";
                                }
            ?> value="P">Pasaporte</option>
                        </select>
                    </div>
                    <div>
                        <label for="NUMERO_ID_C">Identificaci&oacute;n:</label>
                        <input name="NUMERO_ID_C" value="<?php echo $row["NUMERO_ID_C"]; ?>" type="text" id="NUMERO_ID_C"  />
                    </div>
                    <div>
                        <label for="RELACION_C">Relaci&oacute;n Familiar:</label>
                        <select name="RELACION_C" size="1" id="RELACION_C">
                            <option <?php
                                if (!(strcmp("P", $row['RELACION_C']))) {
                                    echo "selected=\"selected\"";
                                } ?> value="P">PADRE</option>
                            <option <?php
                                if (!(strcmp("M", $row['RELACION_C']))) {
                                    echo "selected=\"selected\"";
                                }
            ?> value="M">MADRE</option>
                            <option <?php
                                if (!(strcmp("T", $row['RELACION_C']))) {
                                    echo "selected=\"selected\"";
                                }
            ?> value="T">TIO(A)</option>
                            <option <?php
                                if (!(strcmp("A", $row['RELACION_C']))) {
                                    echo "selected=\"selected\"";
                                }
            ?> value="A">ABUELO(A)</option>
                            <option <?php
                                if (!(strcmp("H", $row['RELACION_C']))) {
                                    echo "selected=\"selected\"";
                                }
            ?> value="H">HERMANO(A)</option>
                        </select>
                    </div>
                    <div>
                        <label for="NOMBRE_C">Nombres:</label>
                        <input name="NOMBRE_C" type="text" value="<?php echo $row["NOMBRE_C"]; ?>" id="NOMBRE_C" size="50" maxlength="100" />
                    </div>
                    <div>
                        <label for="DOCTO_ID_C">Apellidos:</label>
                        <input name="APELLIDO_C"  type="text" id="APELLIDO_C" value="<?php echo $row["APELLIDO_C"]; ?>" size="50" maxlength="100" />
                    </div>
                    <div>
                        <label for="SEXO_C">Sexo:</label>
                        <select name="SEXO_C" size="1" id="SEXO_C">
                            <option value="M" <?php
                                if (!(strcmp("M", $row['SEXO_C']))) {
                                    echo "selected=\"selected\"";
                                }
            ?>>Masculino</option>
                        <option value="F" <?php
                                if (!(strcmp("F", $row['SEXO_C']))) {
                                    echo "selected=\"selected\"";
                                }
            ?>>Femenino</option>
                    </select>
                </div>
                <div>
                    <label for="FEC_NAC_C">Fecha Nacimiento:</label>
                    <input name="FEC_NAC_C" type="text" id="FEC_NAC_C" value="<?php echo $row["FEC_NAC_C"]; ?>" />
                    <input name="STATUS_C" type="hidden" id="STATUS_C" value="1" />
                </div>

            </fieldset>
            <div id="otrosdatos" style=" width: 98%; height: 260px;">
                <div style="width: 45%; float: left;">
                    <table id="hijos"></table>
                </div>
                <div id="pag"></div>
                <div id="alumnos" class="sublist" style="width: 45%; float: left;">
                    <table id="lstalumnos"></table><div id="alpag"></div>
                </div>
                <script type="text/javascript" >
                    (function($){
                        var path=AJAX_CORE_URL+'&operation=listhijos&ID='+$("#ID").val();
                        crearTabla("#hijos","#pag",null,path,"Hijo(a)s",true);
                        $("#hijos").jqGrid('navGrid','#pag',{edit:false,search:true,add:false,del:false});
                        $("#t_hijos").css("height","80px;");
                        $("#t_hijos").append("<input type='button' id='addH' value='Agregar' style='height:20px; font-size:9px;'/>");
                        $("#t_hijos").append("<input type='button' id='delH' value='Quitar' style='height:20px; font-size:9px;'/>");
                        $("#delH").click(function(){ delHijo(); });
                        $("#addH").click(function(){ loadTodos(); });
                        $("#alumnos").hide();
                    })(jQuery);
                </script>
            </div>
        </div>
        <?php
                                foreach ($tabs as $t) {
                                    $ix = $t["ID"];
        ?>
                                    <div id="<?php echo $ix; ?>"  class="TabbedPanelsContent">
                                        <div class="form-container" id="_tab_<?php echo $ix; ?>">
                                            <fieldset>
                    <?php
                                    $builder->build("cllg_parent", $row["ID"], $t['ID']);
                    ?>
                                </fieldset>
                            </div>
            <?php
                                }
            ?>
        </div>
    </div>
</form>
<script type="text/javascript">
    jQuery("#tabs").tabs();
</script>